import { LowcodeServiceApi, OrgServiceApi, ToolServiceApi } from "./_low-code";
import { AxiosResponse } from "axios";
import { objectToUrlParams } from "@/utils/common";
import service from "@/api";
import { InputBean } from "@whjxtech/jxtech-component";
import { randomCoding } from "@/views/low-code/utils/function-util";
import { SYSTEM_CONFIG } from "@/config/system";

export const importFunctionConfigUrl = SYSTEM_CONFIG.BASE_URL + "/lowcode/FunctionService/importFunctionConfig";

export const importDataUrl = SYSTEM_CONFIG.BASE_URL + "/lowcode/DataService/importData";

class FunctionServiceApi extends LowcodeServiceApi {
  saveFunctionMasterDetail(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/saveFunctionMasterDetail";
    url += objectToUrlParams(params, true);
    return service.post(url, bean);
  }
  getDetail(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/getDetail";
    url += objectToUrlParams(params, true);
    return service.get(url, { params: { ...bean } });
  }

  getLowcodeInfo(params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/getLowcodeInfo";
    url += objectToUrlParams(params, true);
    return service.get(url);
  }

  exportFunctionConfig(params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/exportFunctionConfig";
    url += objectToUrlParams(params, true);
    return service.get(url, {
      responseType: "blob"
    });
  }

  removeCache(params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/removeCache";
    url += objectToUrlParams(params, true);
    return service.get(url);
  }
}
export const ExportFunctionServiceApi = new FunctionServiceApi("/FunctionService");
class FunctionGroupServiceApi extends LowcodeServiceApi {}
export const ExportFunctionGroupServiceApi = new FunctionGroupServiceApi("/FunctionGroupService");
class FunctionGroupFieldServiceApi extends LowcodeServiceApi {
  getMainFields(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/getMainFields";
    url += objectToUrlParams(params, true);
    return service.get(url, { params: { ...bean } });
  }
}
export const ExportFunctionGroupFieldServiceApi = new FunctionGroupFieldServiceApi("/FunctionGroupFieldService");
// class PreviewServiceApi extends LowcodeServiceApi {
//   getPreviewData(bean: any, params?: any): Promise<AxiosResponse<any>> {
//     let url = this.baseUrl + "/getPreviewData";
//     url += objectToUrlParams(params, true);
//     return service.get(url, { params: { ...bean } });
//   }
// }
// export const ExportPreviewServiceApi = new PreviewServiceApi(
//   "/PreviewService"
// );

class DataServiceApi extends LowcodeServiceApi {
  pageQueryList(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/pageQueryList";
    url += objectToUrlParams(params, true);
    return service.post(url, bean);
  }

  queryList(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/queryList";
    url += objectToUrlParams(params, true);
    return service.post(url, bean);
  }

  exportQueryList(bean: any, params?: any): Promise<AxiosResponse<Blob>> {
    let url = this.baseUrl + "/exportQueryList";
    url += objectToUrlParams(params, true);
    return service.post(url, bean, {
      responseType: "blob"
    });
  }

  getDetail(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/getDetail";
    url += objectToUrlParams(params, true);
    return service.get(url, { params: { ...bean } });
  }
  save(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/save";
    url += objectToUrlParams(params, true);
    return service.post(url, bean);
  }
  saveMulti(inputBean: InputBean, params?: any): Promise<AxiosResponse<void>> {
    let ids = inputBean.delete?.map(item => item.id);
  }
}
export const ExportDataServiceApi = new DataServiceApi("/DataService");

class DictionaryTypeServiceApi extends OrgServiceApi {
  queryList(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/queryList";
    url += objectToUrlParams(params, true);
    return service.get(url, { params: { ...bean } });
  }
}
export const ExportDictionaryTypeServiceApi = new DictionaryTypeServiceApi("/DictionaryTypeService");

class SeqConfigServiceApi extends ToolServiceApi {
  queryList(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/queryList";
    url += objectToUrlParams(params, true);
    return service.get(url, { params: { ...bean } });
  }
}
export const ExportSeqConfigServiceApi = new SeqConfigServiceApi("/QuerySeqConfigService");

class FieldCandidateServiceApi extends LowcodeServiceApi {
  getFieldCandidates(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/getFieldCandidates";
    url += objectToUrlParams(params, true);
    return service.get(url, { params: { ...bean } });
  }
}
export const ExportFieldCandidateServiceApi = new FieldCandidateServiceApi("/FieldCandidateService");

class FormualService extends LowcodeServiceApi {
  formualCompute(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/formualCompute?_" + randomCoding(6);
    url += "&" + objectToUrlParams(params, true);
    return service.post(url, bean);
  }
}
export const ExportFormualServiceApi = new FormualService("/FormualService");

class HandlerClassService extends LowcodeServiceApi {
  getAllHandlerClass(bean: any, params?: any): Promise<AxiosResponse<any>> {
    let url = this.baseUrl + "/getAllHandlerClass";
    url += objectToUrlParams(params, true);
    return service.get(url, { params: { ...bean } });
  }
}
export const ExportHandlerClassServiceApi = new HandlerClassService("/HandlerClassService");
